﻿using ApplicationFrame.Application;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Modularity;

namespace ApplicationFrame.HostApi
{
    /// <summary>
    /// HostApiAbpModule
    /// </summary>
    [DependsOn(
        typeof(AbpAspNetCoreMvcModule)
        ,typeof(ApplicationAppModule)
        )]
    public class HostApiAppModule: AbpModule
    {
        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            var services = context.Services;
            services.AddControllers();
            services.AddEndpointsApiExplorer();
            services.AddSwaggerGen();
        }

        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public override void OnApplicationInitialization(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();
            var env = context.GetEnvironment();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            
            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseConfiguredEndpoints();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}
